//
//  SISSFindHouseCooperationCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/4/18.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSFindHouseCooperationCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

@interface SISSFindHouseCooperationCell ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *agencyNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *companyLabel;
@property (weak, nonatomic) IBOutlet UILabel *communityAndPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *regionAreaHouseTypeLabel;
@property (strong, nonatomic) IBOutletCollection(UILabel) NSArray *houseTagLabels;
@property (weak, nonatomic) IBOutlet UILabel *ownerPercentLabel;
@property (weak, nonatomic) IBOutlet UILabel *partnerPercentLabel;

@property (weak, nonatomic) IBOutlet UIButton *requestCooperationButton;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *labelsViewHeight;

@end
@implementation SISSFindHouseCooperationCell



- (void)awakeFromNib {
    [super awakeFromNib];
    
    // 设置请求合作按钮的属性
    self.requestCooperationButton.layer.borderWidth = 1;
    self.requestCooperationButton.layer.borderColor = COLOR(0x4D779F).CGColor;
    self.requestCooperationButton.layer.cornerRadius = 4;
    self.requestCooperationButton.layer.masksToBounds = YES;
    [self.requestCooperationButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    [self.requestCooperationButton setBackgroundImage:[ImageWithColor imageWithColor:COLOR(0x4D779F)] forState: UIControlStateHighlighted];
    
    
    
    for (int i = 0; i < 5; i++) {
        UILabel *label = self.houseTagLabels[i];
        label.hidden = YES;
    }
    self.labelsViewHeight.constant = 1;
}

- (void)setHouseCooperationModel:(SISSHouseCooperationModel *)houseCooperationModel {
    
    _houseCooperationModel = houseCooperationModel;
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:houseCooperationModel.portrait] placeholderImage:[UIImage imageNamed:@"头像"]];
    self.agencyNameLabel.text = houseCooperationModel.name;
    self.companyLabel.text = houseCooperationModel.shortName.length ? houseCooperationModel.shortName : houseCooperationModel.organName;
    self.communityAndPriceLabel.text = [NSString stringWithFormat:@"%@ | %@万",houseCooperationModel.neighbourhood,houseCooperationModel.price];
    self.regionAreaHouseTypeLabel.text = [NSString stringWithFormat:@"%@-%@ | %@㎡ | %@",houseCooperationModel.region,houseCooperationModel.regionDetail,houseCooperationModel.area,houseCooperationModel.houseType];
    
    if (houseCooperationModel.listTag.count > 0) {
        self.labelsViewHeight.constant = 24;
    } else {
        self.labelsViewHeight.constant = 1;
    }
    NSArray<UIColor *> *labelCololors = @[COLOR(0x33B189), COLOR(0xF76D81), COLOR(0x8E7FFF), COLOR(0x59ABFD), COLOR(0xE46B00)];
    for (UILabel *label in self.houseTagLabels) {
        label.hidden = YES;
    }
    for (int i = 0; i < houseCooperationModel.listTag.count; i++) {
        UILabel *label = self.houseTagLabels[i];
        label.hidden = NO;
        label.layer.borderWidth = 1;
        label.text = [NSString stringWithFormat:@" %@ ",houseCooperationModel.listTag[i].tag];
        NSInteger colorIndex = houseCooperationModel.listTag[i].color - 1;
        label.layer.borderColor = labelCololors[colorIndex].CGColor;
        label.textColor = labelCololors[colorIndex];
        label.layer.cornerRadius = 2;
        label.layer.masksToBounds = YES;
    }
    
    self.ownerPercentLabel.text = [NSString stringWithFormat:@"%0.f%@",houseCooperationModel.commission_rate,@"%"];
    self.partnerPercentLabel.text = [NSString stringWithFormat:@"%0.f%@",100 -houseCooperationModel.commission_rate,@"%"];
}

/**
 联系按钮点击事件
 */
- (IBAction)contactButtonClickAction:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(findHouseCooperationCell:clickContactButton:)]) {
        [self.delegate findHouseCooperationCell:self clickContactButton:sender];
    }
}

/**
 请求合作按钮点击事件
 */
- (IBAction)requestCooperationButtonClickAction:(UIButton *)sender {
    
    if ([self.delegate respondsToSelector:@selector(findHouseCooperationCell:clickRequestCooperationButton:)]) {
        [self.delegate findHouseCooperationCell:self clickRequestCooperationButton:sender];
    }
}

@end
